home *** CD-ROM | disk | FTP | other *** search
/ Network CD 1 / Network CD.iso / fredfish / 881-890 / ff884 / postsplit / postsplit.c < prev    next >
C/C++ Source or Header  |  1993-07-16  |  8KB  |  353 lines

  1.  
  2. /*
  3.   Name:               postsplit.c
  4.   Processor:          Amiga 68000
  5.   Compiler directive: lc -L xxx.c
  6.   Creation Date:      27 Oct 92
  7.   Version:            1.05
  8.   Author:             I Parker
  9.  
  10.   Description Splits pagestream colour postscript output into separate files
  11.   analyses files and can turn into encapsulated format
  12.  
  13.   Known bugs:- At 'End Page' key words, two cr's are placed
  14.  
  15. */
  16.  
  17. #include <stdio.h>
  18. #include <string.h>
  19.  
  20. #define UNLOCK 0
  21. #define LOCK 1
  22.  
  23. FILE *ifp, *ofp, *fopen();
  24. void Rout1(), Rout2(), Rout3(), Rout4(), Output(), Stop();
  25. char inline[300];
  26. char outline[300];
  27. char drv[46];
  28. int index,a,b;
  29.  
  30.  
  31. main (argc, argv)
  32. int argc;
  33. char *argv[];
  34. {
  35.     if(argc != 3)
  36.     {
  37.     printf("\033[33mpostsplit by I Parker V1.05\n");
  38.              /* \033[33m = prt blue */
  39.     printf("Usage:- postsplit file.ps ([cyan|magenta|yellow|black|spotcolour]\n");
  40.         printf("[anl|fnt|eps])\033[31m\n"); 
  41.              /* \033[31m = reset */
  42.     }
  43.  
  44.     if(argv[2][0] == 'a' && argv[2][1] == 'n' && argv[2][2] == 'l')
  45.     {
  46.     Rout1(argv);
  47.     }
  48.        if(argv[2][0] == 'f' && argv[2][1] == 'n' && argv[2][2] == 't')
  49.     {
  50.     Rout3(argv);
  51.     }
  52.        if(argv[2][0] == 'e' && argv[2][1] == 'p' && argv[2][2] == 's')
  53.    {
  54.    Rout4(argv);
  55.    }
  56.     if(argc == 3)
  57.     {
  58.         Rout2(argv);
  59.     }
  60. } /* end of main */
  61.  
  62. void Rout1(anl) /* routine to analyse the file */
  63. char *anl[];
  64. {
  65. char name[40];
  66. printf("Enter Destination Drive ie RAM:\n");
  67. scanf("%s",&drv);
  68.    if((ifp = fopen(anl[1],"r"))==NULL)
  69.      {
  70.        fprintf(stderr, "Error : Cannot open input file %s\n", strupr(anl[1]));
  71.        exit(-1);
  72.     }
  73.       strcpy(name,anl[1]);
  74.       strcat(name,".anl");
  75.      strcat(drv,name);
  76.  
  77.       if((ofp = fopen(drv, "wb"))==NULL)
  78.         {
  79.         fprintf(stderr, "Error: Unable to open output file %s\n",drv);
  80.         exit(1);
  81.         }
  82.           printf("postscript analysis routine\n");
  83.           while(fgets(inline,300,ifp)!=NULL) /* to end of file */
  84.            {
  85.            index = 0;
  86.             a = 0;
  87.                       for (index=0; inline[index] != '\0'; index++)
  88. switch(inline[index])
  89. {
  90.   case '%': { a=4; } break;
  91.  
  92.   case '!':  {  if(a==4)  {  a=30; Output('\n'); Output(inline[index]);  }  }  break;
  93.  
  94.   case '(':   {   a=2;   }   break;
  95.  
  96.   case '"':  {  if(a==2)  {  a=10; Output('\n'); Output(inline[index]);  }  }  break;
  97.  
  98.   default: if(a > 5) { Output(inline[index]); }
  99.  
  100. } /* end of switch */
  101.  } /* end of while - null */
  102.  
  103.       Stop();
  104. } /* end of rout1 */
  105.  
  106. void Rout2(spl) /* routine to split the file */
  107. char *spl[];
  108. {
  109. char name[40]; /* this is so that the o/p file name can be generated with */
  110.                /* a suffix attached */
  111. int index;
  112. int flag = UNLOCK;
  113. int countbig = 1; /* count beginings */
  114. int countend = 1; /* count endings */
  115. int preq = 0; /* page required */
  116. int pmax = 0; /* maximum page in file */
  117. {
  118.     if(spl[2][0] == 'a' && spl[2][1] == 'n' && spl[2][2] == 'l')
  119.         return;
  120.     if(spl[2][0] == 'e' && spl[2][1] == 'p' && spl[2][2] == 's')
  121.         return;
  122.     if(spl[2][0] == 'f' && spl[2][1] == 'n' && spl[2][2] == 't')
  123.         return;
  124.  
  125. printf("Enter Destination Drive ie DF0:\n");
  126. scanf("%s",&drv);
  127.  
  128.     if((ifp = fopen(spl[1],"r"))==NULL) {
  129.     fprintf(stderr, "Error : Cannot open input file %s\n", strupr(spl[1]));
  130.         exit(-1);
  131.         }
  132.     strcpy(name,spl[1]); /* create o/p file name from i/p names */
  133.     strcat(name,".");
  134.     strcat(name,spl[2]);
  135.    strcat(drv,name);
  136.  
  137.     if((ofp = fopen(drv, "wb"))==NULL) {
  138.     fprintf(stderr, "Error : Unable to open output file %s\n",drv);
  139.     exit(1);
  140.     }
  141.    printf("Enter page number required \n");
  142.    scanf("%d",&preq);
  143.    preq = preq+1;
  144.    printf("Enter maximum page number in file \n");
  145.    scanf("%d",&pmax);
  146.    pmax = pmax+1;
  147.     printf("Splitting postscript file generating %s fragment\n",name);    
  148.     while(fgets(inline,300,ifp)!=NULL)
  149.      {
  150.            index = 0;
  151.             a = 0;
  152.          b = 0;
  153.                       for (index=0; inline[index] != '\0'; index++)
  154. {
  155.    if(countbig < 2)
  156.    {
  157.    Output(inline[index]);
  158.    }
  159.    if(preq == countbig)
  160.    {
  161.    Output(inline[index]);
  162.     }
  163.    if(preq == countend)
  164.    {
  165.    countbig=100;
  166.    }
  167.     if(pmax == countend)
  168.     {
  169.     Output(inline[index]);
  170.     }
  171. switch(inline[index])  /* fine phrase % Begin P*/
  172. {
  173.  case '%': { a=1; } break;
  174.  
  175.  case ' ': { if(a==1) a=2; if(a==7) a=8; } break;
  176.  
  177.  case 'B': { if(a==2) a=3;else a=0; } break;
  178.  
  179.  case 'e': { if(a==3) a=4;else a=0; } break;
  180.  
  181.  case 'g': { if(a==4) a=5;else a=0; } break;
  182.  
  183.  case 'i': { if(a==5) a=6;else a=0; } break;
  184.  
  185.  case 'n': { if(a==6) a=7;else a=0; } break;
  186.  
  187.  case 'P': { if(a==8) {flag = LOCK; a=9;countbig++;}else a=0;} break;
  188.  
  189.  default: break;
  190.  
  191. } /* end of switch */
  192. switch(inline[index])  /* fine phrase % End P*/
  193. {
  194. case '%': { b=11;} break;
  195.  
  196. case ' ': { if(b==11) b=12; if(b==15) b=16; } break;
  197.  
  198. case 'E': { if(b==12) b=13;else b=0; } break;
  199.  
  200. case 'n': { if(b==13) b=14;else b=0; } break;
  201.  
  202. case 'd': { if(b==14) b=15;else b=0; } break;
  203.  
  204. case 'P': { if(b==16) {b=17;}else b=0; } break;
  205.  
  206. case 'a': { if(b==17) {b=18;}else b=0;}break;
  207.  
  208. case 'g': { if(b==18) {b=19;}else b=0;}break;
  209.  
  210. case 'e': { if(b==19) {countend++;}else b=0;}break;
  211.  
  212. default: break;
  213.  
  214. } /* end of else */
  215. } /* end of for */
  216.     }
  217. }
  218.     Stop();
  219. } /* end of rout2 */
  220.  
  221. void Rout3(blc)
  222. char *blc[];
  223. {
  224. char name[40]; /* this is so that the o/p file name can be generated with */
  225.                /* a suffix attached */
  226. int index;
  227. int countfnt = 0;
  228. printf("Enter Destination Drive ie DF0:\n");
  229. scanf("%s",&drv);
  230. {
  231.     if((ifp = fopen(blc[1],"r"))==NULL) {
  232.     fprintf(stderr, "Error : Cannot open input file %s\n", strupr(blc[1]));
  233.         exit(-1);
  234.         }
  235.     strcpy(name,blc[1]); /* create o/p file name from i/p names */
  236.     strcat(drv,name);
  237.    strcat(drv,".FNT");
  238.  
  239.     if((ofp = fopen(drv, "wb"))==NULL) {
  240.     fprintf(stderr, "Error : Unable to open output file %s\n",drv);
  241.     exit(1);
  242.     }
  243.    printf("Extracting adobe font data (other fonts must be done manualy)\n");
  244.     while(fgets(inline,300,ifp)!=NULL)
  245.      {
  246.            index = 0;
  247.             a = 0;
  248.                       for (index=0; inline[index] != '\0'; index++)
  249. {
  250.    if (a==2 && countfnt == 2)
  251.    {
  252.    a=0;
  253.    Output('%');
  254.    Output('!');
  255.    }
  256.     if( countfnt > 1)
  257.     {
  258.     Output(inline[index]);
  259.     }
  260.  
  261. switch(inline[index])  /* fine phrase % Begin P*/
  262. {
  263.  case '%': { a=1; } break;
  264.  
  265.  case '!': { if(a==1) {a=2;countfnt++;}} break;
  266.  
  267.  default: {a=0;break;}
  268. } /* end of switch */
  269.  
  270. } /* end of for */
  271.     }
  272. }
  273.     Stop();
  274. } /* end of rout3 */
  275.  
  276. void Rout4(eps) /* Routine to convert to EPSF format */
  277. char *eps[];
  278. {
  279. char name[40];
  280. int flag = UNLOCK;
  281. printf("Enter Destination Drive ie DFO:\n");
  282. scanf("%s",&drv);
  283.    if((ifp = fopen(eps[1],"r"))==NULL)
  284.      {
  285.        fprintf(stderr, "Error : Cannot open input file %s\n", strupr(eps[1]));
  286.        exit(-1);
  287.     }
  288.       strcpy(name,eps[1]);
  289.       strcat(drv,name);
  290.      strcat(drv,".EPSF");
  291.  
  292.       if((ofp = fopen(drv, "wb"))==NULL)
  293.         {
  294.         fprintf(stderr, "Error: Unable to open output file %s\n",drv);
  295.         exit(1);
  296.         }
  297.       printf("There must be no crop marks and only one page (b/w or col)\n");
  298.       printf("Converting to Encapsulated format\n");
  299.           while(fgets(inline,300,ifp)!=NULL) /* to end of file */
  300.            {
  301.            index = 0;
  302.             a = 0;
  303.                       for (index=0; inline[index] != '\0'; index++)
  304. if (flag==LOCK)
  305. {
  306. Output(inline[index]);
  307. }
  308. if (flag != LOCK)
  309. {
  310. Output ('%');
  311. Output ('!');
  312. Output ('P');
  313. Output ('S');
  314. Output ('-');
  315. Output ('A');
  316. Output ('d');
  317. Output ('o');
  318. Output ('b');
  319. Output ('e');
  320. Output ('-');
  321. Output ('3');
  322. Output ('.');
  323. Output ('0');
  324. Output (' ');
  325. Output ('E');
  326. Output ('P');
  327. Output ('S');
  328. Output ('F');
  329. Output ('-');
  330. Output ('3');
  331. Output ('.');
  332. Output ('0');
  333. Output ('\n');
  334. flag=LOCK;
  335. }
  336.  } /* end of while - null */
  337.  
  338.       Stop();
  339. } /* end of rout4 */
  340.  
  341. void Output(ili)
  342. char ili;
  343. {
  344. putc(ili,ofp);
  345.  
  346. }
  347.  
  348. void Stop()
  349. {
  350. fclose(ifp);
  351. fclose(ofp);
  352. exit();
  353. }